package com.wzs.rpc.server.tcp;

import com.wzs.rpc.server.HttpServer;
import com.wzs.rpc.server.HttpServerHandler;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class VertxTcpServer implements HttpServer {
    @Override
    public void doStart(int port) {
        Vertx vertx = Vertx.vertx();

        vertx.createNetServer()
                .connectHandler(new TcpServerHandler())
                .listen(port)
                .onSuccess(server -> {
                    log.info("HTTP server started on port {}", server.actualPort());
                })
                .onFailure(Throwable::printStackTrace);
    }

    private byte[] handleRequest(byte[] requestBytes) {
        //这里只是一个示例
        return "Hello, world!".getBytes();
    }

    // 测试
    public static void main(String[] args) {
        new VertxTcpServer().doStart(8080);
    }

}
